package com.example.express.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Collection;
import java.util.Objects;

@Entity
@DynamicUpdate
public class TransPackage {
    private String id;
    private Timestamp createTime;
    private Integer status;
    private Collection<PackageRoute> packageRoutes;
    private Collection<TransHistory> transHistories;
    private TransNode source;
    private TransNode target;
    private UserInfo userInfo;
    private Collection<TransPackageContent> transPackageContents;

    @Id
    @Column(name = "ID")
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    @Basic
    @Column(name = "CreateTime")
    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @Basic
    @Column(name = "Status")
    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        TransPackage that = (TransPackage) o;
        return Objects.equals(id, that.id) &&
                Objects.equals(createTime, that.createTime) &&
                Objects.equals(status, that.status);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, createTime, status);
    }

    @JsonIgnore
    @OneToMany(mappedBy = "transPackage")
    public Collection<PackageRoute> getPackageRoutes() {
        return packageRoutes;
    }

    public void setPackageRoutes(Collection<PackageRoute> packageRoutes) {
        this.packageRoutes = packageRoutes;
    }

    @JsonIgnore
    @OneToMany(mappedBy = "transPackage")
    public Collection<TransHistory> getTransHistories() {
        return transHistories;
    }

    public void setTransHistories(Collection<TransHistory> transHistories) {
        this.transHistories = transHistories;
    }

    @ManyToOne
    @JoinColumn(name = "SourceNode", referencedColumnName = "ID")
    public TransNode getSource() {
        return source;
    }

    public void setSource(TransNode source) {
        this.source = source;
    }

    @ManyToOne
    @JoinColumn(name = "TargetNode", referencedColumnName = "ID")
    public TransNode getTarget() {
        return target;
    }

    public void setTarget(TransNode target) {
        this.target = target;
    }

    @ManyToOne
    @JoinColumn(name = "UID", referencedColumnName = "UID")
    public UserInfo getUserInfo() {
        return userInfo;
    }

    public void setUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
    }

    @JsonIgnore
    @OneToMany(mappedBy = "transPackage")
    public Collection<TransPackageContent> getTransPackageContents() {
        return transPackageContents;
    }

    public void setTransPackageContents(Collection<TransPackageContent> transPackageContents) {
        this.transPackageContents = transPackageContents;
    }
}
